<template>
	<view class="video-list">
		<view class="list-container">
			<view class="
				video-item" @click="handleVideoClick(item)" :style="{ backgroundImage: `url(${video.pic})`}">
				<view class=" video-info">
					<view class="video-title u-line-2">{{video.title}}</view>
					<view class="video-meta" v-for="(item, index) in videoList" :key="index">
						<text class="quality">{{item.resName}}:</text>
						<text class="save-btn" @click.stop="handleVideoClick(item)">前往保存</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		history_list,
		getVideoexport,
		support_list
	} from '@/api/user.js'
	export default {
		data() {
			return {
				videoUrl: '',
				videoList: [],
				video: {},
			}
		},
		onLoad() {
			this.videoUrl = uni.getStorageSync('videoUrl')
			// 页面加载时获取视频列表数据
			this.getVideoList()
		},
		methods: {
			// 获取视频列表数据
			async getVideoList() {
				try {
					// 这里替换为实际的API接口
					const response = await getVideoexport({
						url: this.videoUrl,
						device_id: '1111111'
					});

					if (response.code === 1) {
						this.videoList = response.data.res
						this.video = response.data
						uni.setStorageSync('video', response.data)
					}
				} catch (error) {
					uni.showToast({
						title: '获取视频列表失败',
						icon: 'none'
					})
				}
			},

			// 点击视频项
			handleVideoClick(item) {
				uni.setStorageSync('videolist', item)
				if (item.resType == 3) {
					uni.navigateTo({
						url: "/pages/videodetail/videodetail"
					})
				} else if (item.resType == 2) {
					uni.navigateTo({
						url: "/pages/audio/audio"
					})

				} else if (item.resType == 1) {
					uni.navigateTo({
						// url: "/pages/piclist/piclist",
						url:"/pages/image-download/index"
					})
				}


			},

			// 保存视频
			handleSave(item) {
				uni.showLoading({
					title: '保存中...'
				})

				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						title: '保存成功',
						icon: 'success'
					})
				}, 1500)
			}
		}
	}
</script>

<style lang="scss">
	.video-list {
		background-color: #f8f8f8;

		.list-container {
			display: flex;
			flex-direction: column;
			gap: 15px;


			.video-item {
				position: relative;
				width: 100%;
				height: 380rpx;
				background-position: center;
				background-size: 100% 100%;

				.video-info {
					position: absolute;
					bottom: 0;
					left: 0;
					right: 0;
					padding: 20rpx;

					.video-title {
						font-size: 28rpx;
						color: #fff;
						line-height: 1.4;
						margin-bottom: 16rpx;
					}

					.video-meta {
						display: flex;
						// justify-content: space-between;
						align-items: center;
						padding: 10rpx;

						.quality {
							font-size: 28rpx;
							color: #fff;
							padding: 4rpx 12rpx;
							border-radius: 8rpx;
						}

						.save-btn {
							font-size: 20rpx;
							background: #FF7220;
							color: #fff;
							padding: 6rpx 12rpx;
							border-radius: 32rpx;
						}
					}
				}
			}
		}
	}
</style>